package com.hc.contorl;

import com.hc.service.TbUserService;
import com.hc.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/userDelete")
public class UserDeleteContorller extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String pageNum=req.getParameter("pageNum");
        String pageSize=req.getParameter("pageSize");
        String id=req.getParameter("id");
        TbUserService service=new TbUserServiceImpl();
        int line=service.deleteById(Long.parseLong(id));
        System.out.println(line);
        if(line>0){
            req.setAttribute("message","删除成功");

        }else{
            req.setAttribute("message","删除失败");
        }
        req.getRequestDispatcher(String.format("/user_list?pageNum=%s&pageSize=%s",pageNum,pageSize)).forward(req, resp);
    }
}
